<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1> The Ajax 03 Page</h1>
    <button onclick="doAjaxGet()">Do Ajax Get</button>
    <button onclick="doAjaxPost()">Do Ajax Post</button>
    <button onclick="doAjaxDelete()">Do Ajax Delete</button>
    <button onclick="doAjaxUpdate()">Do Ajax Update</button>
    <div id="result"></div>
    <script src="/js/ajax.js"></script>
<script>
    function doAjaxGet() {
        let url="http://localhost/doAjaxGet";
        let params="";
        ajaxGet(url,params,function (result) {
            document.getElementById("result").innerText=result;
        })
    }

    function doAjaxPost() {
        let url="http://localhost/doAjaxPost";
        let params="id=101&name=computer&remark=computer...";
        ajaxPost(url,params,function (result) {
            document.getElementById("result").innerHTML=result;
        })
    }

    function doAjaxDelete() {
        let url="http://localhost/doAjaxDelete";
        let params="id=101";
      ajaxDelete(url,params,function (result) {
            alert(result);
            doAjaxGet();
      })

    }

    function doAjaxUpdate() {
        let url="http://localhost/doAjaxUpdate";
        let params="id=101&name=Boot&remark=Boot...";
        ajaxPut(url,params,function (result) {
            alert(result);
           doAjaxGet();
        })
    }

    // function doAjaxUpdate() {
    //     let xhr=new XMLHttpRequest();
    //     xhr.onreadystatechange=function () {
    //         if(xhr.readyState==4&&xhr.status==200){
    //             document.getElementById("result").innerHTML=xhr.responseText;
    //         }
    //     }
    //     xhr.open("put","http://localhost/doAjaxUpdate",true);
    //     xhr.setRequestHeader("Content-Type",
    //         "application/x-www-form-urlencoded");
    //     xhr.send("id=101&name=Boot&remark=Boot...");//可以null，也可以不传
    // }

</script>
</body>
</html>